 <html>
<head>
<title>~/develope/funny/matrix.pl.html</title>
 <meta name="Generator" content="Vim/6.3">
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 </head>
<body bgcolor="#ffffff" text="#000000">
<pre>
 <font color="#a52a2a">  1</font>  <font color="#a020f0">#!/depot/perl-5.6.1/bin/perl</font>
 <font color="#a52a2a">  2</font>
 <font color="#a52a2a">  3</font>  <font color="#0000ff">############################################################</font>
 <font color="#a52a2a">  4</font>  <font color="#0000ff"># Title : 9*9 Matrix Solving</font>
 <font color="#a52a2a">  5</font>  <font color="#0000ff">#-----------------------------------------------------------</font>
 <font color="#a52a2a">  6</font>  <font color="#0000ff"># By    : Sean Zhang</font>
 <font color="#a52a2a">  7</font>  <font color="#0000ff"># At    : Dec, 2005</font>
 <font color="#a52a2a">  8</font>  <font color="#0000ff"># @     : szhang@synopsys.com</font>
 <font color="#a52a2a">  9</font>  <font color="#0000ff">############################################################</font>
 <font color="#a52a2a"> 10</font>
 <font color="#a52a2a"> 11</font>  <font color="#a52a2a"><b>use </b></font>Data::Dumper;
 <font color="#a52a2a"> 12</font>
 <font color="#a52a2a"> 13</font>  <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">@matrix</font>= init(<font color="#008b8b">$ARGV</font>[<font color="#ff00ff">0</font>]);
 <font color="#a52a2a"> 14</font>
 <font color="#a52a2a"> 15</font>  <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">Problem matrix:</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a"> 16</font>  print_matrix();
 <font color="#a52a2a"> 17</font>
 <font color="#a52a2a"> 18</font>  <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cnt</font> = <font color="#ff00ff">1</font>;
 <font color="#a52a2a"> 19</font>  <font color="#a52a2a"><b>while</b></font>(<font color="#ff00ff">1</font>){
 <font color="#a52a2a"> 20</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$done</font> = do_it();
 <font color="#a52a2a"> 21</font>      <font color="#a52a2a"><b>last</b></font> <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$done</font> == <font color="#ff00ff">1</font> || <font color="#008b8b">$cnt</font> &gt;= <font color="#ff00ff">20</font>;;
 <font color="#a52a2a"> 22</font>      <font color="#008b8b">$cnt</font>++;
 <font color="#a52a2a"> 23</font>  }
 <font color="#a52a2a"> 24</font>  <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a"> 25</font>  <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">After </font><font color="#008b8b">$cnt</font><font color="#ff00ff"> times iteration:</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a"> 26</font>  print_matrix();
 <font color="#a52a2a"> 27</font>  <font color="#a52a2a"><b>exit</b></font>(<font color="#ff00ff">0</font>);
 <font color="#a52a2a"> 28</font>
 <font color="#a52a2a"> 29</font>  <font color="#0000ff">#-------------------------------------------------------------</font>
 <font color="#a52a2a"> 30</font>  <font color="#0000ff">#-------------------------------------------------------------</font>
 <font color="#a52a2a"> 31</font>
 <font color="#a52a2a"> 32</font>  <font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">do_it</font>{
 <font color="#a52a2a"> 33</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$done</font> = <font color="#ff00ff">1</font>;
 <font color="#a52a2a"> 34</font>      <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$i</font>=<font color="#ff00ff">0</font>;<font color="#008b8b">$i</font>&lt;<font color="#ff00ff">9</font>;<font color="#008b8b">$i</font>++){
 <font color="#a52a2a"> 35</font>          <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$j</font>=<font color="#ff00ff">0</font>;<font color="#008b8b">$j</font>&lt;<font color="#ff00ff">9</font>;<font color="#008b8b">$j</font>++){
 <font color="#a52a2a"> 36</font>              check_it(<font color="#008b8b">\@matrix</font>,<font color="#008b8b">$i</font>,<font color="#008b8b">$j</font>);
 <font color="#a52a2a"> 37</font>              fill_it(<font color="#008b8b">\@matrix</font>,<font color="#008b8b">$i</font>,<font color="#008b8b">$j</font>);
 <font color="#a52a2a"> 38</font>              <font color="#008b8b">$done</font> = <font color="#ff00ff">0</font> <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$matrix</font>[<font color="#008b8b">$i</font>][<font color="#008b8b">$j</font>][<font color="#ff00ff">0</font>] <font color="#a52a2a"><b>eq</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a"> 39</font>          }
 <font color="#a52a2a"> 40</font>      }
 <font color="#a52a2a"> 41</font>      <font color="#a52a2a"><b>return</b></font> <font color="#008b8b">$done</font>;
 <font color="#a52a2a"> 42</font>  }
 <font color="#a52a2a"> 43</font>
 <font color="#a52a2a"> 44</font>  <font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">print_matrix</font><font color="#008b8b"> </font>{
 <font color="#a52a2a"> 45</font>      <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">+-------------+-------------+-------------+</font><font color="#ff00ff">'</font>,<font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a"> 46</font>      <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$i</font>=<font color="#ff00ff">0</font>;<font color="#008b8b">$i</font>&lt;<font color="#ff00ff">9</font>;<font color="#008b8b">$i</font>++){
 <font color="#a52a2a"> 47</font>          <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$j</font>=<font color="#ff00ff">0</font>;<font color="#008b8b">$j</font>&lt;<font color="#ff00ff">9</font>;<font color="#008b8b">$j</font>++){
 <font color="#a52a2a"> 48</font>              <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">| </font><font color="#ff00ff">&quot;</font> <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$j</font>==<font color="#ff00ff">0</font>);
 <font color="#a52a2a"> 49</font>              <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$v</font> = <font color="#008b8b">$matrix</font>[<font color="#008b8b">$i</font>][<font color="#008b8b">$j</font>][<font color="#ff00ff">0</font>];
 <font color="#a52a2a"> 50</font>              <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$vf</font> = <font color="#008b8b">$matrix</font>[<font color="#008b8b">$i</font>][<font color="#008b8b">$j</font>][<font color="#ff00ff">10</font>];
 <font color="#a52a2a"> 51</font>              <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$vf</font> <font color="#a52a2a"><b>eq</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">Y</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a"> 52</font>                  <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff"> </font><font color="#008b8b">$v</font><font color="#ff00ff">  </font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a"> 53</font>              }<font color="#a52a2a"><b>else</b></font>{
 <font color="#a52a2a"> 54</font>                  <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">[</font><font color="#008b8b">$v</font><font color="#ff00ff">] </font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a"> 55</font>              }
 <font color="#a52a2a"> 56</font>              <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">| </font><font color="#ff00ff">&quot;</font> <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$j</font>%<font color="#ff00ff">3</font>==<font color="#ff00ff">2</font>);
 <font color="#a52a2a"> 57</font>          }
 <font color="#a52a2a"> 58</font>          <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a"> 59</font>          <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">+-------------+-------------+-------------+</font><font color="#ff00ff">'</font>,<font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font> <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$i</font>%<font color="#ff00ff">3</font>==<font color="#ff00ff">2</font>;
 <font color="#a52a2a"> 60</font>      }
 <font color="#a52a2a"> 61</font>
 <font color="#a52a2a"> 62</font>  }
 <font color="#a52a2a"> 63</font>
 <font color="#a52a2a"> 64</font>  <font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">check_it</font>{
 <font color="#a52a2a"> 65</font>      <font color="#a52a2a"><b>my</b></font> (<font color="#008b8b">$matrix</font>,<font color="#008b8b">$i</font>,<font color="#008b8b">$j</font>) = <font color="#008b8b">@_</font>;
 <font color="#a52a2a"> 66</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$row</font>  = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>];
 <font color="#a52a2a"> 67</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$col</font>  = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>];
 <font color="#a52a2a"> 68</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cell</font> = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>][<font color="#008b8b">$j</font>];
 <font color="#a52a2a"> 69</font>      <font color="#a52a2a"><b>foreach</b></font> <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$k</font> (<font color="#ff00ff">0.</font>.<font color="#ff00ff">8</font>){
 <font color="#a52a2a"> 70</font>         <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$v1</font> = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>][<font color="#008b8b">$k</font>][<font color="#ff00ff">0</font>];
 <font color="#a52a2a"> 71</font>         <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$v2</font> = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$k</font>][<font color="#008b8b">$j</font>][<font color="#ff00ff">0</font>];
 <font color="#a52a2a"> 72</font>         <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$k</font> != <font color="#008b8b">$j</font> &amp;&amp; <font color="#008b8b">$v1</font> <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a"> 73</font>             <font color="#008b8b">$cell</font>-&gt;[<font color="#008b8b">$v1</font>] = <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a"> 74</font>         }
 <font color="#a52a2a"> 75</font>         <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$k</font> != <font color="#008b8b">$i</font> &amp;&amp; <font color="#008b8b">$v2</font> <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a"> 76</font>             <font color="#008b8b">$cell</font>-&gt;[<font color="#008b8b">$v2</font>] = <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a"> 77</font>         }
 <font color="#a52a2a"> 78</font>      }<font color="#0000ff"># end search row and column</font>
 <font color="#a52a2a"> 79</font>
 <font color="#a52a2a"> 80</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$ii</font> = <font color="#a52a2a"><b>int</b></font>(<font color="#008b8b">$i</font>/<font color="#ff00ff">3</font>) ;
 <font color="#a52a2a"> 81</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$ji</font> = <font color="#a52a2a"><b>int</b></font>(<font color="#008b8b">$j</font>/<font color="#ff00ff">3</font>) ;
 <font color="#a52a2a"> 82</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cc_i</font> = <font color="#008b8b">$ii</font>*<font color="#ff00ff">3</font> + <font color="#ff00ff">1</font>;
 <font color="#a52a2a"> 83</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cc_j</font> = <font color="#008b8b">$ji</font>*<font color="#ff00ff">3</font> + <font color="#ff00ff">1</font>;
 <font color="#a52a2a"> 84</font>      <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$ki</font> = <font color="#008b8b">$cc_i</font> - <font color="#ff00ff">1</font>; <font color="#008b8b">$ki</font> &lt;= <font color="#008b8b">$cc_i</font> + <font color="#ff00ff">1</font>; <font color="#008b8b">$ki</font>++){
 <font color="#a52a2a"> 85</font>          <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$kj</font> = <font color="#008b8b">$cc_j</font> - <font color="#ff00ff">1</font>; <font color="#008b8b">$kj</font> &lt;= <font color="#008b8b">$cc_j</font> + <font color="#ff00ff">1</font>; <font color="#008b8b">$kj</font>++){
 <font color="#a52a2a"> 86</font>             <font color="#a52a2a"><b>next</b></font> <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$ki</font> == <font color="#008b8b">$i</font> &amp;&amp; <font color="#008b8b">$kj</font> == <font color="#008b8b">$j</font>;
 <font color="#a52a2a"> 87</font>             <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$v</font> = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$ki</font>][<font color="#008b8b">$kj</font>][<font color="#ff00ff">0</font>];
 <font color="#a52a2a"> 88</font>             <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$v</font> <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a"> 89</font>                 <font color="#008b8b">$cell</font>-&gt;[<font color="#008b8b">$v</font>] = <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a"> 90</font>             }
 <font color="#a52a2a"> 91</font>          }
 <font color="#a52a2a"> 92</font>      }<font color="#0000ff"># end search box</font>
 <font color="#a52a2a"> 93</font>  }
 <font color="#a52a2a"> 94</font>
 <font color="#a52a2a"> 95</font>  <font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">debug</font><font color="#008b8b"> </font>{
 <font color="#a52a2a"> 96</font>      <font color="#a52a2a"><b>local</b></font> <font color="#008b8b">$_</font> = <font color="#a52a2a"><b>shift</b></font>;
 <font color="#a52a2a"> 97</font>      <font color="#a52a2a"><b>return</b></font>;
 <font color="#a52a2a"> 98</font>      <font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">DEBUG: </font><font color="#ff00ff">&quot;</font>,<font color="#008b8b">$_</font>, <font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a"> 99</font>  }
 <font color="#a52a2a">100</font>  <font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">fill_it</font>{
 <font color="#a52a2a">101</font>      <font color="#a52a2a"><b>my</b></font> (<font color="#008b8b">$matrix</font>,<font color="#008b8b">$i</font>,<font color="#008b8b">$j</font>) = <font color="#008b8b">@_</font>;
 <font color="#a52a2a">102</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$row</font>  = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>];
 <font color="#a52a2a">103</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$col</font>  = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>];
 <font color="#a52a2a">104</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cell</font> = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>][<font color="#008b8b">$j</font>];
 <font color="#a52a2a">105</font>      debug(<font color="#ff00ff">&quot;</font><font color="#6a5acd">\$</font><font color="#ff00ff">matrix[</font><font color="#008b8b">$i</font><font color="#ff00ff">][</font><font color="#008b8b">$j</font><font color="#ff00ff">] = </font><font color="#ff00ff">&quot;</font>.<font color="#a52a2a"><b>join</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff"> </font><font color="#ff00ff">&quot;</font>,<font color="#008b8b">@$cell</font>));
 <font color="#a52a2a">106</font>      debug(<font color="#ff00ff">&quot;</font><font color="#6a5acd">\$</font><font color="#ff00ff">matrix[</font><font color="#008b8b">$i</font><font color="#ff00ff">][</font><font color="#008b8b">$j</font><font color="#ff00ff">+1] = </font><font color="#ff00ff">&quot;</font>.<font color="#a52a2a"><b>join</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff"> </font><font color="#ff00ff">&quot;</font>,@{<font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>][<font color="#008b8b">$j</font><font color="#ff00ff">+1</font>]}));
 <font color="#a52a2a">107</font>      <font color="#a52a2a"><b>return</b></font> <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$cell</font>-&gt;[<font color="#ff00ff">0</font>] <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font> ;
 <font color="#a52a2a">108</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$possible</font>   = <font color="#ff00ff">0</font>;
 <font color="#a52a2a">109</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$possible_i</font> = <font color="#ff00ff">0</font>;
 <font color="#a52a2a">110</font>      <font color="#0000ff"># search cell itself</font>
 <font color="#a52a2a">111</font>      <font color="#a52a2a"><b>foreach</b></font> <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$k</font> (<font color="#ff00ff">1.</font>.<font color="#ff00ff">9</font>){
 <font color="#a52a2a">112</font>         <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$cell</font>-&gt;[<font color="#008b8b">$k</font>] <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a">113</font>             <font color="#008b8b">$possible</font> ++;
 <font color="#a52a2a">114</font>             <font color="#008b8b">$possible_i</font> = <font color="#008b8b">$k</font>;
 <font color="#a52a2a">115</font>             debug(<font color="#ff00ff">&quot;</font><font color="#ff00ff">self : </font><font color="#008b8b">$k</font><font color="#ff00ff"> </font><font color="#008b8b">$possible</font><font color="#ff00ff">&quot;</font>);
 <font color="#a52a2a">116</font>             <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$p</font> = check_other(<font color="#008b8b">$matrix</font>,<font color="#008b8b">$i</font>,<font color="#008b8b">$j</font>,<font color="#008b8b">$k</font>);
 <font color="#a52a2a">117</font>             <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$p</font>){
 <font color="#a52a2a">118</font>                 <font color="#008b8b">$cell</font>-&gt;[<font color="#ff00ff">0</font>] = <font color="#008b8b">$k</font> ;
 <font color="#a52a2a">119</font>                 <font color="#a52a2a"><b>return</b></font>;
 <font color="#a52a2a">120</font>             }
 <font color="#a52a2a">121</font>         }
 <font color="#a52a2a">122</font>      }<font color="#0000ff"># end search row and column</font>
 <font color="#a52a2a">123</font>      <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$possible</font> == <font color="#ff00ff">1</font>){
 <font color="#a52a2a">124</font>          <font color="#008b8b">$cell</font>-&gt;[<font color="#ff00ff">0</font>] = <font color="#008b8b">$possible_i</font>;
 <font color="#a52a2a">125</font>          <font color="#a52a2a"><b>return</b></font>;
 <font color="#a52a2a">126</font>      }
 <font color="#a52a2a">127</font>
 <font color="#a52a2a">128</font>
 <font color="#a52a2a">129</font>  }
 <font color="#a52a2a">130</font>
 <font color="#a52a2a">131</font>  <font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">check_other</font>{
 <font color="#a52a2a">132</font>      <font color="#a52a2a"><b>my</b></font> (<font color="#008b8b">$matrix</font>,<font color="#008b8b">$i</font>,<font color="#008b8b">$j</font>,<font color="#008b8b">$value</font>) = <font color="#008b8b">@_</font>;
 <font color="#a52a2a">133</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cnt_row</font> = <font color="#ff00ff">0</font>;
 <font color="#a52a2a">134</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cnt_col</font> = <font color="#ff00ff">0</font>;
 <font color="#a52a2a">135</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cnt_box</font> = <font color="#ff00ff">0</font>;
 <font color="#a52a2a">136</font>
 <font color="#a52a2a">137</font>      <font color="#a52a2a"><b>foreach</b></font> <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$k</font> (<font color="#ff00ff">0.</font>.<font color="#ff00ff">8</font>){
 <font color="#a52a2a">138</font>         <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$v1</font> = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>][<font color="#008b8b">$k</font>][<font color="#ff00ff">0</font>];
 <font color="#a52a2a">139</font>         <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$v2</font> = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$k</font>][<font color="#008b8b">$j</font>][<font color="#ff00ff">0</font>];
 <font color="#a52a2a">140</font>         <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$k</font> != <font color="#008b8b">$j</font>){
 <font color="#a52a2a">141</font>             <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$v1</font> <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a">142</font>                 <font color="#008b8b">$cnt_row</font> ++  <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$v1</font> == <font color="#008b8b">$value</font>
 <font color="#a52a2a">143</font>             }<font color="#a52a2a"><b>else</b></font>{
 <font color="#a52a2a">144</font>                 <font color="#008b8b">$cnt_row</font> ++  <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$i</font>][<font color="#008b8b">$k</font>][<font color="#008b8b">$value</font>] <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a">145</font>             }
 <font color="#a52a2a">146</font>         }
 <font color="#a52a2a">147</font>         <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$k</font> != <font color="#008b8b">$i</font>){
 <font color="#a52a2a">148</font>             <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$v2</font> <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a">149</font>                 <font color="#008b8b">$cnt_col</font> ++  <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$v2</font> == <font color="#008b8b">$value</font>
 <font color="#a52a2a">150</font>             }<font color="#a52a2a"><b>else</b></font>{
 <font color="#a52a2a">151</font>                 <font color="#008b8b">$cnt_col</font> ++  <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$k</font>][<font color="#008b8b">$j</font>][<font color="#008b8b">$value</font>] <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a">152</font>             }
 <font color="#a52a2a">153</font>         }
 <font color="#a52a2a">154</font>      }<font color="#0000ff"># end search row and column</font>
 <font color="#a52a2a">155</font>
 <font color="#a52a2a">156</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$ii</font> = <font color="#a52a2a"><b>int</b></font>(<font color="#008b8b">$i</font>/<font color="#ff00ff">3</font>) ;
 <font color="#a52a2a">157</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$ji</font> = <font color="#a52a2a"><b>int</b></font>(<font color="#008b8b">$j</font>/<font color="#ff00ff">3</font>) ;
 <font color="#a52a2a">158</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cc_i</font> = <font color="#008b8b">$ii</font>*<font color="#ff00ff">3</font> + <font color="#ff00ff">1</font>;
 <font color="#a52a2a">159</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$cc_j</font> = <font color="#008b8b">$ji</font>*<font color="#ff00ff">3</font> + <font color="#ff00ff">1</font>;
 <font color="#a52a2a">160</font>      debug(<font color="#ff00ff">&quot;</font><font color="#ff00ff">cc_i = </font><font color="#008b8b">$cc_i</font><font color="#ff00ff">   cc_j = </font><font color="#008b8b">$cc_j</font><font color="#ff00ff">&quot;</font>);
 <font color="#a52a2a">161</font>      <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$ki</font> = <font color="#008b8b">$cc_i</font> - <font color="#ff00ff">1</font>; <font color="#008b8b">$ki</font> &lt;= <font color="#008b8b">$cc_i</font> + <font color="#ff00ff">1</font>; <font color="#008b8b">$ki</font>++){
 <font color="#a52a2a">162</font>          <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$kj</font> = <font color="#008b8b">$cc_j</font> - <font color="#ff00ff">1</font>; <font color="#008b8b">$kj</font> &lt;= <font color="#008b8b">$cc_j</font> + <font color="#ff00ff">1</font>; <font color="#008b8b">$kj</font>++){
 <font color="#a52a2a">163</font>             <font color="#a52a2a"><b>next</b></font> <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$ki</font> == <font color="#008b8b">$i</font> &amp;&amp; <font color="#008b8b">$kj</font> == <font color="#008b8b">$j</font>;
 <font color="#a52a2a">164</font>             <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$v</font> = <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$ki</font>][<font color="#008b8b">$kj</font>][<font color="#ff00ff">0</font>];
 <font color="#a52a2a">165</font>             <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$v</font> <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a">166</font>                 <font color="#008b8b">$cnt_box</font> ++  <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$v</font> == <font color="#008b8b">$value</font> ;
 <font color="#a52a2a">167</font>             }<font color="#a52a2a"><b>else</b></font>{
 <font color="#a52a2a">168</font>                 <font color="#008b8b">$cnt_box</font> ++  <font color="#a52a2a"><b>if</b></font> <font color="#008b8b">$matrix</font>-&gt;[<font color="#008b8b">$ki</font>][<font color="#008b8b">$kj</font>][<font color="#008b8b">$value</font>] <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a">169</font>             }
 <font color="#a52a2a">170</font>          }
 <font color="#a52a2a">171</font>      }<font color="#0000ff"># end search box</font>
 <font color="#a52a2a">172</font>      debug(<font color="#ff00ff">&quot;</font><font color="#ff00ff">cnt_row = </font><font color="#008b8b">$cnt_row</font><font color="#ff00ff"> || cnt_col = </font><font color="#008b8b">$cnt_col</font><font color="#ff00ff"> || cnt_box = </font><font color="#008b8b">$cnt_box</font><font color="#ff00ff">&quot;</font>);
 <font color="#a52a2a">173</font>      <font color="#a52a2a"><b>return</b></font> <font color="#008b8b">$cnt_row</font> == <font color="#ff00ff">0</font> || <font color="#008b8b">$cnt_col</font> == <font color="#ff00ff">0</font> || <font color="#008b8b">$cnt_box</font>==<font color="#ff00ff">0</font>;
 <font color="#a52a2a">174</font>  }
 <font color="#a52a2a">175</font>
 <font color="#a52a2a">176</font>  <font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">init</font>{
 <font color="#a52a2a">177</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$file</font> = <font color="#a52a2a"><b>shift</b></font>;
 <font color="#a52a2a">178</font>
 <font color="#a52a2a">179</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">@matrix</font> = ();
 <font color="#a52a2a">180</font>      <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$fp</font> = \*DATA;
 <font color="#a52a2a">181</font>      <font color="#a52a2a"><b>if</b></font>(<font color="#a52a2a"><b>defined</b></font>(<font color="#008b8b">$file</font>)){
 <font color="#a52a2a">182</font>          <font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">F</font>,<font color="#008b8b">$file</font>) || <font color="#a52a2a"><b>die</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">Error: can not open file &lt;</font><font color="#008b8b">$file</font><font color="#ff00ff">&gt;. </font><font color="#008b8b">$!</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
 <font color="#a52a2a">183</font>          <font color="#008b8b">$fp</font> = \*F;
 <font color="#a52a2a">184</font>      }
 <font color="#a52a2a">185</font>      <font color="#a52a2a"><b>while</b></font>(&lt;<font color="#008b8b">$fp</font>&gt;){
 <font color="#a52a2a">186</font>          <font color="#a52a2a"><b>next</b></font> <font color="#a52a2a"><b>if</b></font><font color="#a52a2a"><b> /</b></font><font color="#ff00ff">^</font><font color="#6a5acd">\s</font><font color="#6a5acd">*</font><font color="#ff00ff">$</font><font color="#a52a2a"><b>/</b></font>;
 <font color="#a52a2a">187</font>          <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">@toks</font> = <font color="#a52a2a"><b>split</b></font>(<font color="#a52a2a"><b>/</b></font><font color="#6a5acd">\s</font><font color="#6a5acd">+</font><font color="#a52a2a"><b>/</b></font>,<font color="#008b8b">$_</font>);
 <font color="#a52a2a">188</font>          <font color="#a52a2a"><b>for</b></font>(<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$i</font>=<font color="#ff00ff">0</font>;<font color="#008b8b">$i</font>&lt;<font color="#ff00ff">9</font>;<font color="#008b8b">$i</font>++){
 <font color="#a52a2a">189</font>              <font color="#008b8b">$toks</font>[<font color="#008b8b">$i</font>] = [<font color="#008b8b">$toks</font>[<font color="#008b8b">$i</font>],<font color="#ff00ff">1.</font>.<font color="#ff00ff">9</font>];
 <font color="#a52a2a">190</font>              <font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$toks</font>[<font color="#008b8b">$i</font>]-&gt;[<font color="#ff00ff">0</font>] <font color="#a52a2a"><b>ne</b></font> <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>){
 <font color="#a52a2a">191</font>                 <font color="#a52a2a"><b>foreach</b></font> <font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$f</font> (<font color="#ff00ff">1.</font>.<font color="#ff00ff">9</font>){
 <font color="#a52a2a">192</font>                     <font color="#008b8b">$toks</font>[<font color="#008b8b">$i</font>]-&gt;[<font color="#008b8b">$f</font>] = <font color="#ff00ff">'</font><font color="#ff00ff">x</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a">193</font>                 }
 <font color="#a52a2a">194</font>                 <font color="#008b8b">$toks</font>[<font color="#008b8b">$i</font>]-&gt;[<font color="#008b8b">$toks</font>[<font color="#008b8b">$i</font>]-&gt;[<font color="#ff00ff">0</font>]] = <font color="#ff00ff">1</font>;
 <font color="#a52a2a">195</font>                 <font color="#008b8b">$toks</font>[<font color="#008b8b">$i</font>]-&gt;[<font color="#ff00ff">10</font>] = <font color="#ff00ff">'</font><font color="#ff00ff">Y</font><font color="#ff00ff">'</font>;
 <font color="#a52a2a">196</font>              }
 <font color="#a52a2a">197</font>          }
 <font color="#a52a2a">198</font>          <font color="#a52a2a"><b>push</b></font> <font color="#008b8b">@matrix</font>, <font color="#008b8b">\@toks</font>;
 <font color="#a52a2a">199</font>      }
 <font color="#a52a2a">200</font>      <font color="#a52a2a"><b>close</b></font>(<font color="#008b8b">$fp</font>);
 <font color="#a52a2a">201</font>      <font color="#a52a2a"><b>return</b></font> <font color="#008b8b">@matrix</font>;
 <font color="#a52a2a">202</font>  }
 <font color="#a52a2a">203</font>
 <font color="#a52a2a">204</font>  <font color="#0000ff">__DATA__</font>
 <font color="#a52a2a">205</font>  <font color="#0000ff">4       x       x       x       7       x       x       x       2</font>
 <font color="#a52a2a">206</font>  <font color="#0000ff">x       8       x       x       x       x       x       1       x</font>
 <font color="#a52a2a">207</font>  <font color="#0000ff">x       x       x       9       3       5       x       x       x</font>
 <font color="#a52a2a">208</font>  <font color="#0000ff">x       x       7       x       x       x       5       x       x</font>
 <font color="#a52a2a">209</font>  <font color="#0000ff">5       x       4       x       9       x       6       x       3</font>
 <font color="#a52a2a">210</font>  <font color="#0000ff">x       x       8       x       x       x       2       x       x</font>
 <font color="#a52a2a">211</font>  <font color="#0000ff">x       x       x       8       5       3       x       x       x</font>
 <font color="#a52a2a">212</font>  <font color="#0000ff">x       5       x       x       x       x       x       3       x</font>
 <font color="#a52a2a">213</font>  <font color="#0000ff">9       x       x       x       4       x       x       x       7</font>
 <font color="#a52a2a">214</font>
 <font color="#a52a2a">215</font>
 <font color="#a52a2a">216</font>
 <font color="#a52a2a">217</font>  <font color="#0000ff">Problem matrix:</font>
 <font color="#a52a2a">218</font>  <font color="#0000ff">+-------------+-------------+-------------+</font>
 <font color="#a52a2a">219</font>  <font color="#0000ff">| [x]  1  [x] |  3  [x] [x] | [x]  6  [x] |</font>
 <font color="#a52a2a">220</font>  <font color="#0000ff">|  5   9   6  | [x]  7  [x] |  4   3  [x] |</font>
 <font color="#a52a2a">221</font>  <font color="#0000ff">| [x] [x] [x] | [x] [x]  4  | [x]  8  [x] |</font>
 <font color="#a52a2a">222</font>  <font color="#0000ff">+-------------+-------------+-------------+</font>
 <font color="#a52a2a">223</font>  <font color="#0000ff">| [x] [x]  1  | [x] [x] [x] | [x] [x]  8  |</font>
 <font color="#a52a2a">224</font>  <font color="#0000ff">| [x]  6  [x] | [x] [x] [x] | [x]  2  [x] |</font>
 <font color="#a52a2a">225</font>  <font color="#0000ff">|  2  [x] [x] | [x] [x] [x] |  5  [x] [x] |</font>
 <font color="#a52a2a">226</font>  <font color="#0000ff">+-------------+-------------+-------------+</font>
 <font color="#a52a2a">227</font>  <font color="#0000ff">| [x]  3  [x] |  4  [x] [x] | [x] [x] [x] |</font>
 <font color="#a52a2a">228</font>  <font color="#0000ff">| [x]  4   2  | [x]  6  [x] |  8   9   1  |</font>
 <font color="#a52a2a">229</font>  <font color="#0000ff">| [x]  5  [x] | [x] [x]  1  | [x]  7  [x] |</font>
 <font color="#a52a2a">230</font>  <font color="#0000ff">+-------------+-------------+-------------+</font>
 <font color="#a52a2a">231</font>
 <font color="#a52a2a">232</font>
 <font color="#a52a2a">233</font>  <font color="#0000ff">After 5 times iteration:</font>
 <font color="#a52a2a">234</font>  <font color="#0000ff">+-------------+-------------+-------------+</font>
 <font color="#a52a2a">235</font>  <font color="#0000ff">| [8]  1  [4] |  3  [5] [2] | [9]  6  [7] |</font>
 <font color="#a52a2a">236</font>  <font color="#0000ff">|  5   9   6  | [1]  7  [8] |  4   3  [2] |</font>
 <font color="#a52a2a">237</font>  <font color="#0000ff">| [3] [2] [7] | [6] [9]  4  | [1]  8  [5] |</font>
 <font color="#a52a2a">238</font>  <font color="#0000ff">+-------------+-------------+-------------+</font>
 <font color="#a52a2a">239</font>  <font color="#0000ff">| [9] [7]  1  | [2] [3] [5] | [6] [4]  8  |</font>
 <font color="#a52a2a">240</font>  <font color="#0000ff">| [4]  6  [5] | [8] [1] [9] | [7]  2  [3] |</font>
 <font color="#a52a2a">241</font>  <font color="#0000ff">|  2  [8] [3] | [7] [4] [6] |  5  [1] [9] |</font>
 <font color="#a52a2a">242</font>  <font color="#0000ff">+-------------+-------------+-------------+</font>
 <font color="#a52a2a">243</font>  <font color="#0000ff">| [1]  3  [9] |  4  [8] [7] | [2] [5] [6] |</font>
 <font color="#a52a2a">244</font>  <font color="#0000ff">| [7]  4   2  | [5]  6  [3] |  8   9   1  |</font>
 <font color="#a52a2a">245</font>  <font color="#0000ff">| [6]  5  [8] | [9] [2]  1  | [3]  7  [4] |</font>
 <font color="#a52a2a">246</font>  <font color="#0000ff">+-------------+-------------+-------------+</font>
 <font color="#a52a2a">247</font>
 </pre>
</body>
</html>
